# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union


class DocsEnum:
    # 文件状态
    FILE_WAIT = 0  # 等待中
    FILE_ING = 1   # 解析中
    FILE_YES = 2   # 解析成功
    FILE_FAIL = 3  # 解析失败


class MusicEnum:
    # 状态
    STATUS_WAIT = 0  # 等待中
    STATUS_ING = 1   # 生成中
    STATUS_YES = 2   # 生成成功
    STATUS_FAIL = 3  # 生成失败

    # 音乐引擎
    ENGINE_SUNO = "suno"

    # 音乐通道
    OPENAI_HK = "openai_hk"

    @classmethod
    def get_channels(cls):
        """ 音乐通道 """
        return {
            cls.OPENAI_HK: "Suno(HK)"
        }

    @classmethod
    def get_logo(cls, code: Union[str, bool] = True):
        """ 通道图标 """
        _desc = {
            cls.OPENAI_HK: "static/models/draws_zsy.png"
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")


class VideoEnum:
    # 生成状态
    STATUS_WAIT = 0  # 等待中
    STATUS_ING = 1   # 生成中
    STATUS_YES = 2   # 生成成功
    STATUS_FAIL = 3  # 生成失败

    # 生成类型
    TYPE_TEXT_TO_VIDEO = "text2video"  # 文生视频
    TYPE_IMAGE_TO_VIDEO = "img2img"  # 图生视频

    # 视频引擎
    ENGINE_LUMA = "luma"
    ENGINE_ZHIPU = "zhipu"

    # 视频通道
    OPENAI_HK = "openai_hk"
    ZHIPU = "zhipu"

    @classmethod
    def get_channels(cls):
        return {
            "luma-hk": "Luma(HK)",
            "zhipu": "智谱视频"
        }

    @classmethod
    def get_logo(cls, code: Union[str, bool] = True):
        """ 语音通道图标 """
        _desc = {
            "luma-hk": "static/models/draws_zsy.png",
            "zhipu": "static/models/draws_zsy.png"
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")


class DrawsEnum:
    # 状态
    STATUS_WAIT = 0  # 等待中
    STATUS_ING = 1   # 生成中
    STATUS_YES = 2   # 生成成功
    STATUS_FAIL = 3  # 生成失败

    # 绘画引擎
    ENGINE_SD = "sd"
    ENGINE_MJ = "mj"
    ENGINE_DALLE = "dalle"
    ENGINE_DOUBAO = "doubao"

    # 绘画类型
    TYPE_TEXT_TO_IMAGE = "text2img"         # 文生图
    TYPE_IMAGE_TO_IMAGE = "img2img"         # 图生图
    TYPE_UPSCALE_IMAGE = "upscale2img"      # 图变大
    TYPE_VARIATION_IMAGE = "variation2img"  # 图变换

    # 绘画操作
    ACTION_GENERATE = "generate"    # 生图
    ACTION_UPSAMPLE = "upsample"    # 放大
    ACTION_VARIATION = "variation"  # 变换

    @classmethod
    def get_channels(cls):
        return {
            "mj-zsy-relax": "MJ知数云(慢速)",
            "mj-zsy-fast": "MJ知数云(快速)",
            "mj-zsy-turbo": "MJ知数云(极速)",
            "mj-acedata": "MJ绘画(AceData)",
            "dalle": "DALLE绘画",
            "doubao": "豆包绘画",
        }

    @classmethod
    def get_logo(cls, code: Union[str, bool] = True):
        """ 语音通道图标 """
        _desc = {
            "mj-zsy-relax": "static/models/draws_zsy.png",
            "mj-zsy-fast": "static/models/draws_zsy.png",
            "mj-zsy-turbo": "static/models/draws_zsy.png",
            "mj-acedata": "static/models/draws_ace.png",
            "dalle": "static/models/draws_dalle.png",
            "doubao": "static/models/draws_doubao.png"
        }
        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def mj_config(cls, code):
        _desc = {
            # 模型选项
            "models": [
                {
                    "key": "mj",
                    "name": "Midjourney",
                    "desc": "真实感强",
                    "bg": "static/images/draws_mj.png"
                },
                {
                    "key": "niji",
                    "name": "Niji",
                    "desc": "卡通动漫",
                    "bg": "static/images/draws_nj.png"
                }
            ],
            # MJ模式
            "mj_mode": {
                "fast": "快速",
                "relax": "慢速",
                "turbo": "极速"
            },
            # MJ风格
            "mj_style": {
                "default": "动漫",
                "expressive": "丰富",
                "scenic": "风景",
                "cute": "可爱"
            },
            # MJ质量
            "mj_quality": {
                1: "1",
                .5: "0.5",
                .25: "0.25"
            },
            # MJ版本
            "mj_version": {
                "mj": [
                    "6.1",
                    "6.0",
                    "5.2",
                    "5.1",
                    "5",
                    "4"
                ],
                "niji": [
                    "6",
                    "5"
                ]
            },
            # 高级参数
            "complex_params": {
                "iw": {
                    "type": "slider",
                    "name": "参考图权重",
                    "tips": "(iw)设置生成图片时垫图的权重，值越大越像垫图，取值范围0.5-2，默认值1",
                    "step": 0.1,
                    "range": [0.5, 2],
                    "default": 25
                },
                "q": {
                    "type": "slider",
                    "name": "图片质量",
                    "tips": "(q)设置图片的质量，越大质量越高，取值范围0.25-1，默认值1",
                    "step": 0.1,
                    "range": [0.25, 1],
                    "default": 1
                },
                "s": {
                    "type": "slider",
                    "name": "风格化值",
                    "tips": "(s)设置生成图片时的风格化程度V值越大，风格化的程度越高，取值范围0-100，默认值100。",
                    "step": 1,
                    "range": [0, 100],
                    "default": 100
                },
                "c": {
                    "type": "slider",
                    "name": "随机程度",
                    "tips": "(s)数值越大随机性越高，较低则还是按照描述词走，默认值0。",
                    "step": 1,
                    "range": [0, 100],
                    "default": 0
                },
                "seed": {
                    "type": "number",
                    "name": "随机种子",
                    "tips": "种子用于指定生成效果, 可以用于生成套图, 保障生成的一系列图片保持同一种风格, 默认: -1",
                    "placeholder": "请输入seed种子编号",
                    "default": -1
                }
            }
        }

        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")

    @classmethod
    def doubao_config(cls, code):
        _desc = {
            # 模型选项
            "models": [
                {
                    "key": "high_aes_general_v21_L",
                    "name": "文生图",
                    "desc": "",
                    "bg": "static/images/draws_mj.png"
                },
                {
                    "key": "i2i_xl_sft",
                    "name": "图生图",
                    "desc": "",
                    "bg": "static/images/draws_nj.png"
                },
                {
                    "key": "high_aes",
                    "name": "动漫图",
                    "desc": "",
                    "bg": "static/images/draws_dm.png"
                }
            ],
            # 文生图2.1
            "high_aes_general_v21_L": {
                "refer_img": False,
                "version": {
                    "general_v20_9B_pe": "美感版",
                    "general_v20_9B_rephraser": "标准版"
                },
                "complex_params": {
                    "ddim_steps": {
                        "type": "slider",
                        "name": "图像质量",
                        "tips": "设置图片的质量，越大质量越高，默认值25",
                        "step": 1,
                        "range": [1, 200],
                        "default": 25
                    },
                    "scale": {
                        "type": "slider",
                        "name": "描述影响",
                        "tips": "影响文本描述的程度，默认值3.5",
                        "step": 0.1,
                        "range": [1, 10],
                        "default": 3.5
                    },
                    "seed": {
                        "type": "number",
                        "name": "随机种子",
                        "tips": "种子用于指定生成效果, 可以用于生成套图, 保障生成的一系列图片保持同一种风格, 默认: -1",
                        "placeholder": "请输入seed种子编号",
                        "default": -1
                    }
                }
            },
            # 图生图XL-Pro
            "i2i_xl_sft": {
                "refer_img": True,
                "complex_params": {
                    "ddim_steps": {
                        "type": "slider",
                        "name": "图像质量",
                        "tips": "设置图片的质量，越大质量越高，默认值20",
                        "step": 1,
                        "range": [1, 50],
                        "default": 20
                    },
                    "scale": {
                        "type": "slider",
                        "name": "描述影响",
                        "tips": "影响文本描述的程度，默认值7.0",
                        "step": 0.1,
                        "range": [1, 30],
                        "default": 7.0
                    },
                    "seed": {
                        "type": "number",
                        "name": "随机种子",
                        "tips": "种子用于指定生成效果, 可以用于生成套图, 保障生成的一系列图片保持同一种风格, 默认: -1",
                        "placeholder": "请输入seed种子编号",
                        "default": -1
                    }
                }
            },
            # 动漫图1.3X
            "high_aes": {
                "refer_img": True,
                "version": {
                    "1.3.1": "anime_v1.3.1",
                    "1.3": "anime_v1.3"
                },
                "complex_params": {
                    "ddim_steps": {
                        "type": "slider",
                        "name": "图像质量",
                        "tips": "设置图片的质量，越大质量越高，默认值20",
                        "step": 1,
                        "range": [1, 50],
                        "default": 20
                    },
                    "scale": {
                        "type": "slider",
                        "name": "描述影响",
                        "tips": "影响文本描述的程度，默认值7.0",
                        "step": 0.1,
                        "range": [1, 30],
                        "default": 7.0
                    },
                    "strength": {
                        "type": "slider",
                        "name": "接近原图",
                        "tips": "越小越接近原图，越大越接近文本控制，默认值0.7",
                        "step": 0.1,
                        "range": [0, 1.0],
                        "default": 0.7
                    },
                    "seed": {
                        "type": "number",
                        "name": "随机种子",
                        "tips": "种子用于指定生成效果, 可以用于生成套图, 保障生成的一系列图片保持同一种风格, 默认: -1",
                        "placeholder": "请输入seed种子编号",
                        "default": -1
                    }
                }
            }
        }

        if isinstance(code, bool) and code:
            return _desc
        return _desc.get(code, "")
